﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZX.HIS.Model;
using ZX.HIS.BLL;
using ZX.HIS.Common;
using ZX.HIS.SQLServerDAL;

namespace ZX.HIS.UI.Controllers
{
    public class AuthorInfoController : Controller
    {
        //
        // GET: /AuthorInfo/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult addAuthorInfo()
        {
            ZX.HIS.BLL.UserInfo bll2 = new BLL.UserInfo();
            List<ZX.HIS.Model.AuthorInfo> list1 = new List<Model.AuthorInfo>();
            ZX.HIS.Model.AuthorInfo AIModel = new ZX.HIS.Model.AuthorInfo();
            AIModel.AuthorId = 0;
            AIModel.AuthorName = "请选择";
            list1.Add(AIModel);
            List<ZX.HIS.Model.AuthorInfo> list = bll2.allAuthorInfo();
            foreach (ZX.HIS.Model.AuthorInfo item in list)
            {
                list1.Add(item);
            }
            ViewBag.AuthorParentId = new SelectList(list1, "AuthorId", "AuthorName");
            return View();
        }

        public ActionResult updUserInfo(int id)
        {
            //权限表实体类
            ZX.HIS.BLL.AuthorInfo bll = new BLL.AuthorInfo();
            ZX.HIS.Model.AuthorInfo model = bll.GetAuthorInfoModel(id);
            ViewBag.AuthorInfo = model;

            //父级下拉框
            ZX.HIS.BLL.UserInfo bll2 = new BLL.UserInfo();

        
            List<ZX.HIS.Model.AuthorInfo> list1 = new List<Model.AuthorInfo>();
            ZX.HIS.Model.AuthorInfo AIModel = new ZX.HIS.Model.AuthorInfo();
            AIModel.AuthorId = 0;
            AIModel.AuthorName = "请选择";
            list1.Add(AIModel);

            List<ZX.HIS.Model.AuthorInfo> list = bll2.allAuthorInfo();
            foreach (ZX.HIS.Model.AuthorInfo item in list)
            {
                list1.Add(item);
            }

            ZX.HIS.Model.AuthorInfo AuthorInfo = list.Where(p => p.AuthorId == id).FirstOrDefault();
            int AuthorParentId = Convert.ToInt32(AuthorInfo.AuthorParentId);

            ViewBag.AuthorParentId = new SelectList(list1, "AuthorId", "AuthorName", AuthorParentId);

          
            return View();
        }
        /// <summary>
        /// 分页显示
        /// </summary>
        /// <returns></returns>
        public ActionResult FnshowAuthorInfo()
        {
            ZX.HIS.BLL.AuthorInfo bll = new BLL.AuthorInfo();
            int PageIndex = Convert.ToInt32(Request["a"]);
            int PageSize = Convert.ToInt32(Request["b"]);

            PageClass<ZX.HIS.Model.AuthorInfo> p = bll.allAuthorInfo(PageIndex, PageSize);

            return Json(p);
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <returns></returns>
        public int FnaddUserInfodo()
        {
            ZX.HIS.BLL.AuthorInfo bll = new BLL.AuthorInfo();
            int HospitalId=0;
            HttpCookie myCookie = Request.Cookies["MyCookie"];
            if (myCookie != null)
            {
                if (!String.IsNullOrEmpty(myCookie["HospitalId"]))
                {
                    HospitalId = Convert.ToInt32(myCookie["HospitalId"]);
                }
            }
            string AuthorName = Request["AuthorName"].ToString();
            string AuthorUrl = Request["AuthorUrl"].ToString();
            int AuthorParentId = Convert.ToInt32(Request["AuthorParentId"]);
            int AuthorState = Convert.ToInt32(Request["AuthorState"]);
            if (bll.addAuthorInfo(HospitalId, AuthorName, AuthorUrl, AuthorParentId, AuthorState) == true)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        /// <summary>
        /// 修改状态
        /// </summary>
        /// <returns></returns>
        public int FndelUserInfo()
        {
            ZX.HIS.BLL.AuthorInfo bll = new BLL.AuthorInfo();
            int AuthorId = Convert.ToInt32(Request["AuthorId"]);
            int state = Convert.ToInt32(Request["state"]);
            if (bll.delAuthorInfo(AuthorId, state) == true)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        /// <summary>
        /// 修改数据
        /// </summary>
        /// <returns></returns>
        public int FnupdUserInfodo()
        {
            ZX.HIS.BLL.AuthorInfo bll = new BLL.AuthorInfo();
            int AuthorId = Convert.ToInt32(Request["AuthorId"]);
            string AuthorName = Request["AuthorName"].ToString();
            string AuthorUrl = Request["AuthorUrl"].ToString();
            int AuthorParentId = Convert.ToInt32(Request["AuthorParentId"]);
            if (bll.updAuthorInfo(AuthorId, AuthorName, AuthorUrl, AuthorParentId) == true)
            {
                return 1;
            }
            else
            {
                return 0;
            }

        }
    }
}
